package org.jeecg.modules.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.biz.entity.EventBet;
import org.jeecg.modules.biz.entity.EventSettle;
import org.jeecg.modules.biz.mapper.EventSettleMapper;
import org.jeecg.modules.biz.service.EventBetService;
import org.jeecg.modules.biz.service.EventSettleService;
import org.jeecg.modules.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 结算任务 接口实现
 */

@Slf4j
@Service
public class EventSettleServiceImpl extends ServiceImpl<EventSettleMapper, EventSettle> implements EventSettleService {
    @Autowired
    private EventSettleMapper settleMapper;
    @Autowired
    private EventBetService betService;

    @Override
    public EventSettle getLatestOne() {
        return settleMapper.getLatestOne();
    }

    @Override
    public boolean saveAndUpdateEventBet(EventSettle eventSettle, String dateStr) {
        this.save(eventSettle);
        DateFormat format = new SimpleDateFormat("yyyyMMdd");
        try {
            dateStr = TimeUtils.formatDate(format.parse(dateStr), "yyyy-MM-dd");
            betService.updateIsSettleByCallerAndDate(eventSettle.getCaller(), dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return true;
    }

    @Override
    public List<String> findCallerListByInviter(String inviter) {
        return settleMapper.findCallerListByInviter(inviter);
    }
}
